<?php
/*
*description:接口（发送）
*author:李飞@天众科技
*time:2016/12/29
*/
namespace Admin\Controller;
use Think\Controller;
class PushsendapiController extends Controller {
	//推送转换单
    public function productorderPush(){
		$this->db_config(session('warehouse_code'));
		$m=M('ProductOrder',C('DB_PRS'),C('DB_DEPOT'));
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('ProductOrderDetail',C('DB_PRS'),C('DB_DEPOT'));
		$b=M('ProductOrderByproduct',C('DB_PRS'),C('DB_DEPOT'));
		$erp_code=I('erp_code');
		$id=I('id');
		$arr=explode(',',$id);
		$list_goods=array();
		foreach($arr as $ks=>$vs){
			$order_info=$m->find($vs);//当前id对应主产品详情
			$order_infolist=$n->where(array('plan_id'=>$vs))->select();
			$by_list=$b->where(array('order_id'=>$vs))->select();
			foreach($order_infolist as $k=>$v){
				$goods_info=$ao->where(array('goods_id'=>$v))->find();
				$order_infolist[$k]['goods_no']=$goods_info['goods_no'];
				$order_infolist[$k]['goods_name']=$goods_info['goods_name'];
			}
			$goods_info['warehouse_code']=session('warehouse_code');
			$list_goods[$ks]=$goods_info;
			$list_goods[$ks]['order_infolist']=$order_infolist;
			$list_goods[$ks]['by_list']=$by_list;
		}
		$url =C('BASE_CONFIG.productorderPush');//推送库存接口地址;
        $res = $this->push($url,$list_goods);
		
		$ress=json_decode($res,true);
		
		if(!$ress['flag']){
			$return['info']=$ress['data']['message'];
			$return['status']=false; 
			$this->ajaxReturn($return);
		}else{
			$m->where(array('id'=>array('in',$arr)))->setField(array('push_time'=>time(),'push_times'=>array('exp','push_times+1')));
			$return['info']='推送成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
		}
	}
	//实收数据接口(跨境)
	public function realsendCrossborder(){
		
		$this->db_config(session('warehouse_code'));
        $plan_id = I('param.id','','trim');

        $m = M('ArrivalOrderPlan',C('DB_PRS'),C('DB_DEPOT'));
        $n = M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
        $plan_info = $m->field('old_order_no,receive_no,status,receive_apply_status')->find($plan_id);
		// echo $m->getlastsql();
		// die;
		if($plan_info['receive_apply_status']==1){
			$text='已申报通过不能重复申报';
			$return['flag']=0;
			$return['tip']=$text;
			$this->ajaxReturn($return);
		}
		if($plan_info['status']<>1){
			$text='未审核通过不能申报';
			$return['flag']=0;
			$return['tip']=$text;
			$this->ajaxReturn($return);
		}

        $data = array();
        $plan_detail_info = $n->field('source_no,receive_amount,arrival_time as in_time,bound_cate_code,mark,conforming_p,nonconforming_p,scrap_one,scrap_two,goods_no')->where(array('plan_id'=>$plan_id))->select();
		// echo $n->getlastsql();
		// die;
        $data['plan_detail_info'] = $plan_detail_info;
		$data['plan_info'] = $plan_info;
		$url = C('BASE_CONFIG.realsendCrossborder2');//出库申报
        $res = $this->send_curl($url,$data);
		//file_put_contents('./log/realsend.log',date('Y-m-d H:i:s').var_export($res,true).PHP_EOL,FILE_APPEND);//日志导出sql
		
		$json=json_decode($res,true);
		if($json['flag']==1){//成功
			$m->where(array('id'=>$plan_id))->setField('receive_apply_status',1);//更新实收申报状态
		}
		if($json['flag']==0){//失败
			$m->where(array('id'=>$plan_id))->setField('receive_apply_status',2);//更新实收申报状态
		}
        return $json;
    }
	//入库申报
	public function realsendCrossborderinbound(){
		
		$this->db_config(session('warehouse_code'));
        $plan_id = I('param.id','','trim');

        $m = M('ArrivalOrderPlan',C('DB_PRS'),C('DB_DEPOT'));
        $n = M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
        $plan_info = $m->find($plan_id);
		
		if($plan_info['plan_apply_status']==1){
			$text='已申报通过不能重复申报';
			$return['flag']=0;
			$return['tip']=$text;
			$this->ajaxReturn($return);
		}
		if($plan_info['status']<>1){
			$text='未审核通过不能申报';
			$return['flag']=0;
			$return['tip']=$text;
			$this->ajaxReturn($return);
		}
		$receive_no =$plan_info['receive_no'];
        $data = array();
        $plan_detail_info = $n->field("'".$receive_no."' as receive_no,source_no,receive_amount,arrival_time as in_time,bound_cate_code as bound_status")->where(array('plan_id'=>$plan_id))->select();
		// echo $n->getlastsql();
		// die;
		
        $data['plan_detail_info'] = $plan_detail_info;
		
		// dump($data);
		$url = C('BASE_CONFIG.realsendCrossborder');//出库申报
		
		// dump(json_encode($data));
		// die;
        $res = $this->send_curl($url,$data);
		//file_put_contents('./log/realsend.log',date('Y-m-d H:i:s').var_export($res,true).PHP_EOL,FILE_APPEND);//日志导出sql
		$json=json_decode($res,true);
		if($json['flag']==1){//成功
			$m->where(array('id'=>$plan_id))->setField('plan_apply_status',1);//更新实收申报状态
		}
		if($json['flag']==0){//失败
			$m->where(array('id'=>$plan_id))->setField('plan_apply_status',2);//更新实收申报状态
		}
        return $json;//成功

    }
	//账册申请信息审核---发送--砍掉
    public function booksOrderSend(){
		$this->db_config(session('warehouse_code'));
		$m=M('BooksCate',C('DB_PRS'),C('DB_DEPOT'));
		$id=I('id');
		$ids=explode(',',$id);
		$map['id']=array('in',$ids);
		$data['info']=$m->field('code,status,erp_code')->where($map)->select();

		file_put_contents('./log/1.log',date('Y-m-d H:i:s').var_export($data,true).PHP_EOL,FILE_APPEND);//日志导出sql
		$url = C('BASE_CONFIG.booksOrderSend');//接口地址
        $res = $this->push($url,$data);
		file_put_contents('./log/2.log',date('Y-m-d H:i:s').var_export($res,true).PHP_EOL,FILE_APPEND);//日志导出sql
		
		$status=json_decode($res,true);
		
		// dump($status);
        if($status['flag']){
			$i=0;
			foreach($status as $k=>$v){
				$maps['old_books_id']=$k;
				foreach($v as $key=>$value){
					if($value['is_true']==1){
						$i++;
						$m->where($maps)->setInc('push_success_times',1);
					}
				}
			}
			$datas['push_arrival_time']=time();//更新推送时间
			$datas['push_arrival_times']=array('exp','push_arrival_times+1');
			$ress=$m->where($map)->save($datas);
			$return['status']=1;
			$return['info']=$i.'条推送成功！';
			//dump($return);
			$this->ajaxReturn($return);
        }else{
			$return['status']=0;
			$return['info']='推送失败！';

			$this->ajaxReturn($return);
        }
	}
	//账册详情产品信息审核---发送
    public function booksinfoOrderSend(){
		$this->db_config(session('warehouse_code'));
		$m=M('Books',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('BooksCate',C('DB_PRS'),C('DB_DEPOT'));
		$id=I('id');
		$ids=explode(',',$id);
		$map['id']=array('in',$ids);
		$data['info']=$m->field('manua_id,status,goods_no')->where($map)->select();
		// file_put_contents('./log/aa.log',date('Y-m-d H:i:s').$m->getlastsql().PHP_EOL,FILE_APPEND);//日志导出sql
		foreach($data['info'] as $k=>$v){
			$erp=$n->where(array('code'=>$v['manua_id']))->find();
			$data['info'][$k]['erp_code']=$erp['erp_code'];
		}
		$url =C('BASE_CONFIG.booksinfoOrderSend');//接口地址
        $res = $this->push($url,$data);
		
		file_put_contents('./log/bb.log',date('Y-m-d H:i:s').var_export($res,true).PHP_EOL,FILE_APPEND);//日志导出sql
		$status=json_decode($res,true);
		//dump($status);
        if($status['flag']){
			$i=0;
			foreach($status as $k=>$v){
				$maps['goods_no']=$v['goods_no'];
				foreach($v as $key=>$value){
					if($value['is_true']==1){
						$i++;
						$m->where($maps)->setInc('push_success_times',1);
					}
				}
			}
			$datas['push_arrival_time']=time();//更新推送时间
			$datas['push_arrival_times']=array('exp','push_arrival_times+1');
			$ress=$m->where($map)->save($datas);
			$return['status']=1;
			$return['info']=$i.'条推送成功！';
			//dump($return);
			$this->ajaxReturn($return);
        }else{
			$return['status']=0;
			$return['info']='推送失败！';

			$this->ajaxReturn($return);
        }
	}
	//其它入库推送仓库接口----发送
    public function pushDepot(){
		$this->db_config(session('warehouse_code'));
		$m=M('MoveDepot',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('Warehouse');
		$f=M('MoveDepotInfo',C('DB_PRS'),C('DB_DEPOT'));
		$g=M('Goods',C('DB_PRS'),C('DB_DEPOT'));
		
		$id=I('id');
		$ids=explode(',',$id);
		$map['id']=array('in',$ids);
		$list=$m->where($map)->select();
		$arr=array();
		foreach($list as $k=>$v){
			if($v['status']!=1){
				$return['status']=0;
				$return['info']="单号[".$v['order_no']."]未审核通过不能推送";
				$this->ajaxReturn($return);
			}
			$info=$f->where(array('order_id'=>$v['id']))->select();
			foreach($info as $kk=>$vv){
				$ss=$g->where(array('id'=>$vv['goods_id']))->find();
				$ss['nums']=$vv['nums'];//调拨数量
				$goods_info[]=$ss;
			}
			$v['goods']=$goods_info;

			$warehouse_list=$n->field('url,warehouse_code')->where(array('warehouse_code'=>$v['depot_code']))->find();//取得仓库url地址
			$arr[$warehouse_list['url']]['info'][]=$v;//根据url地址重新分组
			$arr[$warehouse_list['url']]['warehouse_code']=$warehouse_list['warehouse_code'];//根据url地址重新分组
		}
		// dump($arr);
		// die;
		$suss=0;
		$fal=0;
		foreach($arr as $key=>$value){
			// $url="http://".$key.'/index.php/Pushsendapi/receiveDepot';
			// $res = $this->push($url,$value);
			$res=$this->receiveDepot($value);
			// dump($res);
			// die;
			//file_put_contents('./log/realsend.log',date('Y-m-d H:i:s').var_export($res,true).PHP_EOL,FILE_APPEND);//日志导出sql
			$status=json_decode($res,true);
			//dump($status);
			if($status['status'] == 1){
				foreach($value as $ks=>$vs){
					$where['id']=$vs['id'];
					$datas['push_time']=time();//更新推送时间
					$datas['push_times']=array('exp','push_times+1');
					$ress=$m->where($where)->save($datas);
				}
				$suss++;//成功条数
			}else{
				$fal++;//失败条数
			}
		}
		$return['status']=1;
		$return['info']=$suss.'条推送成功！'.$fal."条失败";
		$this->ajaxReturn($return);
	}
	//其它入库推送仓库入库--自定义函数
    public function receiveDepot($datas){
		$this->db_config(session('warehouse_code'));
		$n=M('Warehouse');
		$param=$datas;
		$t_no=serialNumber('MoveDepot');//流水号
		$order_no='MD'.date('Ymd',time()).$t_no;//流水单号
		
		
			
			$warehouse_code=$param['warehouse_code'];
			
			$info=$n->where(array('warehouse_code'=>$warehouse_code))->find();
			
			if($info){  //天众数据库库配置
				!empty($info['db_ip'])?$db_ip=$info['db_ip']:$db_ip=C('DEPOT_DB_HOST');
				!empty($info['db_name'])?$db_name=$info['db_name']:$db_name=C('DEPOT_DB_NAME');
				!empty($info['db_username'])?$db_username=$info['db_username']:$db_username=C('DEPOT_DB_USER');
				!empty($info['db_password'])?$db_password=$info['db_password']:$db_password=C('DEPOT_DB_PWD');
				!empty($info['db_port'])?$db_port=$info['db_port']:$db_port=C('DEPOT_DB_PORT');
				!empty($info['db_pre'])?$db_pre=$info['db_pre']:$db_pre=C('DEPOT_DB_PREFIX');
				
				//当前仓库数据库配置
				C('DB_S.DB_TYPE','mysql');
				C('DB_S.DB_HOST',$db_ip);
				C('DB_S.DB_NAME',$db_name);
				C('DB_S.DB_USER',$db_username);
				C('DB_S.DB_PWD',$db_password);
				C('DB_S.DB_PORT',$db_port);
				C('DB_PRSS',$db_pre);
				C('DB_S.DB_CHARSET','utf8');
				$m=M('ArrivalOrder',C('DB_PRSS'),C('DB_S'));
			}
			
			foreach($param['info'] as $kk => $vv){
			
				foreach($vv['goods'] as $k => $v){
					$list['order_no']=$order_no;
					$list['old_purchasing_no']=$vv['order_no'];
					$list['old_goods_id']=$v['id'];
					$list['manual_id']=$v['manua_id'];
					$list['bound_cate_code']='DB';
					$list['goods_no']=$v['goods_no'];
					$list['goods_name']=$v['goods_name'];
					$list['amount']=$v['nums'];

					// $list['expected_time']=$v['expected_time'];
					$list['add_time']=time();
					$status=$m->add($list);//到货通知单添加
					// echo $m->getlastsql();
					if($status){
						continue;
					}else{
						$return['status']=0;
						$return['info']="添加失败";
						$this->ajaxReturn($return);
					}
				}
			}

		
		$return['status']=1;
		$return['info']="添加成功";
		$this->ajaxReturn($return);
	}

	//到货实收数据接口----发送
	public function realsend(){
		$this->db_config(session('warehouse_code'));
		$m = M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
        $id = I('param.id','','trim');
		if(empty($id)) $this->error("请选择要推送的数据");//为空
        $arr=explode(',', $id);
        $map['id']=array('in',$arr);
        $data['info'] = $m->where($map)->select();
		// file_put_contents('./log/vv.log',date('Y-m-d H:i:s').var_export($m->getlastsql(),true).PHP_EOL,FILE_APPEND);//日志导出sql
		if(!$data['info']){
			$return['status']=0;
			$return['info']="到货通知单不存在";
			$this->ajaxReturn($return);
        }
        $url =C('BASE_CONFIG.realsend');//接口地址;
        $res = $this->push($url,$data);
		//file_put_contents('./log/realsend.log',date('Y-m-d H:i:s').var_export($res,true).PHP_EOL,FILE_APPEND);//日志导出sql
		$status=json_decode($res,true);
		//dump($status);
        if(!empty($status)){
			$i=0;
			foreach($status as $k=>$v){
				$maps['old_goods_id']=$k;
				$maps['erp_code']=$v['erp_code'];
				foreach($v as $key=>$value){
					if($value['is_true']==1){
						$i++;
						$m->where($maps)->setInc('push_success_times',1);
						file_put_contents('./log/realsend.log',date('Y-m-d H:i:s').$m->getlastsql().PHP_EOL,FILE_APPEND);//日志导出sql
					}
				}
			}
			$datas['push_arrival_time']=time();//更新推送时间
			$datas['push_arrival_times']=array('exp','push_arrival_times+1');
			$ress=$m->where($map)->save($datas);
			// echo $m->getlastsql();
			$return['status']=1;
			$return['info']=$i.'条推送成功！';
			//dump($return);
			$this->ajaxReturn($return);
        }else{
			$return['status']=0;
			$return['info']='推送失败！';
			$this->ajaxReturn($return);
        }
    }
	//商品上架数据----发送
	public function grounding(){
		$this->db_config(session('warehouse_code'));
		$m = M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
        $id = I('id');
		if(empty($id)) $this->error("请选择要推送的数据");//为空
        $arr=explode(',', $id);
        $map['id']=array('in',$arr);
        $data = $m->field('old_goods_id,erp_code')->where($map)->select();
		// echo $m->getlastsql();
		if(!$data){
			$return['status']=0;
			$return['info']="上架商品不存在";
			$this->ajaxReturn($return);
        }
		
        $url =C('BASE_CONFIG.grounding');//接口地址;
        $res = $this->push($url,$data);
		// dump($res);
		// die;
		$ress=json_decode($res,true);
		if(!$ress['flag']){
			$return['info']='已推送过了!';
			$return['status']=false; 
			$this->ajaxReturn($return);
		}else{
			$data_m['push_grounding_time']=time();
			$data_m['push_grounding_times']=array('exp','push_grounding_times+1');
			$m->where($map)->save($data_m);
			$return['info']='推送成功!';
			$return['status']=true;
			$this->ajaxReturn($return);
		}
    }
	//出库申报接口（更新申报信息）
	public function get_method(){
		$id=I('id');
		$info=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'))->where(array('id'=>$id))->find();
		
		$url=C('BASE_CONFIG.get_method');//更新出库信息

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		//post传值数据
		curl_setopt($ch, CURLOPT_POST, 1);
		//post的变量
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('logistics_no'=>$info['logistics_no'])));
		$output = curl_exec($ch);
		curl_close($ch);
		$res= json_decode($output,true);
		if($res['flag']){//成功
			$data_out['push_outboundstatus']=1;
			$data_out['push_outboundtime']=time();
			$status=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'))->where(array('id'=>$id))->save($data_out);
			if($status!==false){
				$return['status']=1;
				$return['message']='成功';
				$this->ajaxReturn($return);
			}else{
				$data_out['push_outboundstatus']=0;
				$status=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'))->where(array('id'=>$id))->save($data_out);//回滚操作
				$return['status']=0;
				$return['message']='失败';
				$this->ajaxReturn($return);
			}
		}else{//失败
			$return['status']=0;
			$return['message']=$res['tip'];
			$this->ajaxReturn($return);
		}
    }
	//批量出库申报接口（更新申报信息）
	public function get_methodbatch(){
		$ids=I('id');
		$map['p.id']=array('in',$ids);
		$p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$pa=M('Packing',C('DB_PRS'),C('DB_DEPOT'));
		$g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$list=$p->alias('p')->field('id,logistics_no,order_no')->where($map)->select();
		$arr=array();
		foreach($list as $k=>$v){
			$arr[$k]['logistics_no']=$v['logistics_no'];
			$arr[$k]['pack_weight']=$pa->where(array('order_no'=>$v['order_no']))->getField('pack_weight');
			$goods_no=$g->where(array('order_id'=>$v['id']))->limit(1)->getField('goods_no');
			$arr[$k]['merchant_code']=substr($goods_no,0,9);
		}
		$url=C('BASE_CONFIG.get_methodbatch');//批量更新出库信息

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		//post传值数据
		curl_setopt($ch, CURLOPT_POST, 1);
		//post的变量
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('data'=>$arr)));
		$output = curl_exec($ch);
		curl_close($ch);
		$res= json_decode($output,true);
		
		$data_out=array();
		if($res['flag']){//申报成功
			$data_out['push_outboundstatus']=1;
			$data_out['push_outboundtime']=time();
			$status=$p->alias('p')->where($map)->save($data_out);
			if($status!==false){
				$return['status']=1;
				$return['message']='成功';
				$this->ajaxReturn($return);
			}else{
				// $data_out['push_outboundstatus']=0;
				// $status=$p->alias('p')->where($map)->save($data_out);//回滚操作
				$return['status']=0;
				$return['message']='失败';
				$this->ajaxReturn($return);
			}
		}else{//失败
			$data_out['push_outboundstatus']=0;
			$status=$p->alias('p')->where($map)->save($data_out);//回滚操作
			$return['status']=0;
			$return['message']=$res['tip'];
			$this->ajaxReturn($return);
		}
    }
	
	//批量出库申报接口（更新申报信息）--其它出库
	public function get_methodbatch_otheroutbound(){
		$id=I('id');
		$map['p.id']=$id;
		$p=M('otherOutbound',C('DB_PRS'),C('DB_DEPOT'));
		$g=M('otherOutboundInfo',C('DB_PRS'),C('DB_DEPOT'));
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		$info=$p->alias('p')->field('id,order_no,out_status,push_status')->where($map)->find();
		$arr=array();

		if(!$info['out_status']){
			$return['status']=0;
			$return['message']=$info['order_no'].'未出库不能申报';
			$this->ajaxReturn($return);
		}
		
		if($info['push_status']){
			$return['status']=0;
			$return['message']=$info['order_no'].'已申报不能再次申报';
			$this->ajaxReturn($return);
		}
		$arr['order_no']=$info['order_no'];
		$maps=[];
		$maps['g.order_id']=$info['id'];
		$arr['detail']=$g->alias('g')->field('g.unit_count,ao.bar_code,g.outbound_cate_no')->join("__ARRIVAL_ORDER__ ao on g.goods_id=ao.id")->where($maps)->select();
		
		$url=C('OMS_URL').C('otheroutbound_out');//批量更新出库信息

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		//post传值数据
		curl_setopt($ch, CURLOPT_POST, 1);
		//post的变量
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('data'=>$arr)));
		$output = curl_exec($ch);
		curl_close($ch);
		$res= json_decode($output,true);
		
		$data_out=array();
		if($res['flag']){//申报成功
			$data_out['push_status']=1;
			// $data_out['push_outboundtime']=time();
			$status=$p->alias('p')->where($map)->save($data_out);
			if($status!==false){
				$return['status']=1;
				$return['message']='成功';
				$this->ajaxReturn($return);
			}else{
				$data_out['push_status']=0;
				$status=$p->alias('p')->where($map)->save($data_out);//回滚操作
				$return['status']=0;
				$return['message']='失败';
				$this->ajaxReturn($return);
			}
		}else{//失败
			$data_out['push_status']=0;
			$status=$p->alias('p')->where($map)->save($data_out);//回滚操作
			$return['status']=0;
			$return['message']=$res['tip'];
			$this->ajaxReturn($return);
		}
    }
	//推送当前商品库存到对应账册的erp
    public function synch_goods(){
		$this->db_config(session('warehouse_code'));
		$m=M('Goods',C('DB_PRS'),C('DB_DEPOT'));
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		$b=M('Books',C('DB_PRS'),C('DB_DEPOT'));
		$bc=M('BooksCate',C('DB_PRS'),C('DB_DEPOT'));
		$id=I('id');
		$arr=explode(',',$id);
		$list_goods=array();
		foreach($arr as $ks=>$vs){
			$goods_info=$m->find($vs);//当前id对应库存详情
			$books_info=$b->where(array('manua_id'=>$goods_info['manua_id'],'goods_no'=>$goods_info['goods_no']))->find();
			if(empty($books_info)){
				$return['info']='找不到对应的账册信息，不能推送！';
				$return['status']=false; 
				$this->ajaxReturn($return);
			}else{
				$bookscate_info=$bc->where(array('code'=>$goods_info['manua_id']))->find();
				$goods_info['erp_code']=$bookscate_info['erp_code'];//找到对应erp_code的值
			}
			$map['grounding_status']=1;//已上架
			$map['manual_id']=$goods_info['manua_id'];
			$map['goods_no']=$goods_info['goods_no'];
			$ao_list=$ao->where($map)->select();
			if(empty($ao_list)){
				$return['info']='商品编码'.$goods_info['goods_no'].'没有对应商品上架信息，不能推送!';
				$return['status']=false; 
				$this->ajaxReturn($return);
			}
			$goods_info['warehouse_code']=session('warehouse_code');
			$list_goods[$ks]=$goods_info;
			$list_goods[$ks]['goods_info_list']=$ao_list;
		}
		$url =C('BASE_CONFIG.synch_goods');//推送库存接口地址;
        $res = $this->push($url,$list_goods);
		
		$ress=json_decode($res,true);
		
		if(!$ress['flag']){
			$return['info']=$ress['data']['message'];
			$return['status']=false; 
			$this->ajaxReturn($return);
		}else{
			$m->where(array('id'=>array('in',$arr)))->setField(array('push_time'=>time(),'push_times'=>array('exp','push_times+1')));
			$return['info']='推送成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
		}
	}
	public function push($url,$post_data){
		// file_put_contents('./log/3.log',date('Y-m-d H:i:s').var_export($post_data,true).PHP_EOL,FILE_APPEND);//日志导出sql
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
		
		$output = curl_exec($ch);
		// dump($output);
		// die;
		curl_close($ch);
		return $output;
	}
	public  function send_curl($url,$data){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //post传值数据
        curl_setopt($ch, CURLOPT_POST, 1);
        //post的变量
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('data'=>json_encode($data))));
        $output = curl_exec($ch);

        curl_close($ch);
        return $output;
    }
	/*
	 *获取数据库配置
     */
    public function db_config($warehouse_code){
		
		$info=M('Warehouse')->where(array('warehouse_code'=>$warehouse_code))->find();//获取配置表中对应域名的id
		$ss=M('Warehouse')->getlastsql();
		file_put_contents('./log/info.log',date('Y-m-d H:i:s').var_export($ss,true).PHP_EOL,FILE_APPEND);//日志导出sql
		// echo M()->getlastsql();
		
		// dump($info);
		if($info){  //天众数据库库配置
			!empty($info['db_ip'])?$db_ip=$info['db_ip']:$db_ip=C('DEPOT_DB_HOST');
			!empty($info['db_name'])?$db_name=$info['db_name']:$db_name=C('DEPOT_DB_NAME');
			!empty($info['db_username'])?$db_username=$info['db_username']:$db_username=C('DEPOT_DB_USER');
			!empty($info['db_password'])?$db_password=$info['db_password']:$db_password=C('DEPOT_DB_PWD');
			!empty($info['db_port'])?$db_port=$info['db_port']:$db_port=C('DEPOT_DB_PORT');
			!empty($info['db_pre'])?$db_pre=$info['db_pre']:$db_pre=C('DEPOT_DB_PREFIX');
			
			//当前仓库数据库配置
			C('DB_DEPOT.DB_TYPE','mysql');
			C('DB_DEPOT.DB_HOST',$db_ip);
			C('DB_DEPOT.DB_NAME',$db_name);
			C('DB_DEPOT.DB_USER',$db_username);
			C('DB_DEPOT.DB_PWD',$db_password);
			C('DB_DEPOT.DB_PORT',$db_port);
			C('DB_PRS',$db_pre);
			C('DB_DEPOT.DB_CHARSET','utf8');
		}
		
		//加载自定义配置信息
		$m=M('Config',C('DB_PRS'),C('DB_DEPOT'));
		$list=$m->where(array('status'=>1))->getField('en_name,value');
		C('base_config',$list);
    }
}